package app.k.com.kframedemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import app.k.com.kframedemo.R;

/**
 * Created by mac_wk on 14-12-26.
 */
public class Fragment2 extends Fragment {
    private View rootView;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        if (rootView==null)
        {
            rootView = inflater.inflate(R.layout.tab_layout,null);
            final TextView textView = (TextView) rootView.findViewById(R.id.textView);
            textView.setText("hello tab 2");
            textView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    textView.append(" press");
                }
            });
        }
        ViewGroup parent = (ViewGroup) rootView.getParent();
        if (parent != null) {
            parent.removeView(rootView);
        }

        return rootView;
    }
}
